﻿namespace DeploymentCustomActions
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// List of Constants
    /// </summary>
    public static class Constants
    {
        public const string BiztalkCatalogUrl = "server={0};database={1};Integrated Security=SSPI";
        public const string BiztalkInstallPath = "BiztalkInstallPath";
        public const string RepairSuffix = "_repair.msi";
        public const string UninstallSuffix = "_uninstall.msi";
        public const string BiztalkInternalInstallDir = "BIZTALKINTERNALINSTALLDIR";
        
        public static class BiztalkApplication
        {
            public const string Id = "Id";
            public const string ApplicationName = "ApplicationName";
            public const string Query = "SELECT `Id` , `ApplicationName`, `Component_`, `BiztalkManagementInstanceName` , `BiztalkManagementDatabaseName`, `BackupLocation` FROM `BiztalkApplications`";
            public const string BiztalkApplications = "BiztalkApplications";
            public const string BiztalkManagementInstanceName = "BiztalkManagementInstanceName";
            public const string BiztalkManagementDatabaseName = "BiztalkManagementDatabaseName";
            public const string ComponentName = "Component_";
            public const string BackupLocation = "BackupLocation";
        }
            
        public static class BiztalkApplicationResources
        {
            public const string Id = BiztalkApplication.Id;
            public const string BiztalkApplicationId = "BiztalkApplicationId";
            public const string FilePath = "FilePath";
            public const string BiztalkResourceType = "BiztalkResourceType";
            public const string Query = "SELECT `Id` , `BiztalkApplicationId`, `FilePath` , `BiztalkResourceType` FROM `BiztalkApplicationResources`";
            public const string BiztalkResourceDestinationFormat = "%BTAD_InstallDir%\\{0}";
            public const string ErrorSystemApplicationUpdate = "System applications can not be changed!";
        }

        public static class BiztalkApplicationReferences
        {
            public const string BiztalkApplicationId = BiztalkApplicationResources.BiztalkApplicationId;
            public const string ApplicationName = BiztalkApplication.ApplicationName;
            public const string Query = "SELECT `BiztalkApplicationId`, `ApplicationName` FROM `BiztalkApplicationReferences`";
        }

        public static class BamActivities
        {
            public const string BamActivitiesTable = "BamActivities";
            public const string Query = "SELECT `Component_`, `Source`, `DropOnUninstall`, `BamInstanceName`, `BamDatabaseName`, `ActivityWindow`, `ViewAccessAccounts` FROM `BamActivities`";
            public const string ComponentName = BiztalkApplication.ComponentName;
            public const string Source = "Source";
            public const string DropOnUninstall = "DropOnUninstall";
            public const string BamInstanceName = "BamInstanceName";
            public const string BamDatabaseName = "BamDatabaseName";
            public const string BamArchiveInstanceName = "BamArchiveInstanceName";
            public const string BamArchiveDatabaseName = "BamArchiveDatabaseName";
            public const string ActivityWindow = "ActivityWindow";
            public const string ViewAccessAccounts = "ViewAccessAccounts";            

            public const string BamNamespace = "http://schemas.microsoft.com/BizTalkServer/2004/10/BAM";

            public static string GetBamActivityBackupLocation(string bamInstanceName)
            {
                return bamInstanceName + "Backup";
            }

            public static string GetBamActivityExistingList(string bamInstanceName)
            {
                return bamInstanceName + "Activity";
            }
        }

        internal static class VsDbCmd10
        {
            public const string Query = "SELECT `Id` , `Component_`, `ConnectionString` , `DatabaseName` , `DatabaseSchemaProvider`, `DeploymentConfigurationFile`, `ModelFile`, `SqlCmdVarsFile`, `PostDeploymentScript`, `PreDeploymentScript` FROM `VsDbCmd10`";
            public const string SqlCmdVariablesQuery = "SELECT `VsDbCmd10Id` , `Name`, `Value` FROM `VsDbCmd10SqlCmdVariables`";

            public const string Id = BiztalkApplication.Id;
            public const string ComponentName = BiztalkApplication.ComponentName;
            public const string ConnectionString = "ConnectionString";
            public const string DatabaseName = "DatabaseName";
            public const string DatabaseSchemaProvider = "DatabaseSchemaProvider";
            public const string DeploymentConfigurationFile = "DeploymentConfigurationFile";
            public const string ModelFile = "ModelFile";
            public const string SqlCmdVarsFile = "SqlCmdVarsFile";
            public const string PostDeploymentScript = "PostDeploymentScript";
            public const string PreDeploymentScript = "PreDeploymentScript";

            public const string VsDbCmd10Id = "VsDbCmd10Id";
            public const string Name = "Name";
            public const string Value = "Value";

            public const string VsDbCmdBinaryPath = "VsDbCmdBinaryPath";
            public const string VsDbCmdBinaryContent = "VsDbCmdBinaryContent";
            public static string GetExtractFolder(string path)
            {
                return path + ".Extract";
            }
        }

        internal static class SqlCmd
        {
            public const string Query = "SELECT `Id` , `Component_`, `ConnectionString` , `QueryType` , `QueryString`, `Sequence`, `SqlCmdId`, `Condition` FROM `SqlCmd`";
            public const string SqlCmdVariablesQuery = "SELECT `SqlCmdId` , `Name`, `Value` FROM `SqlCmdVariables`";

            public const string Id = BiztalkApplication.Id;
            public const string ComponentName = BiztalkApplication.ComponentName;
            public const string ConnectionString = VsDbCmd10.ConnectionString;
            public const string QueryType = "QueryType";
            public const string QueryString = "QueryString";
            public const string Sequence = "Sequence";
            public const string SqlCmdId = "SqlCmdId";
            public const string Condition = "Condition";

            public const string Name = "Name";
            public const string Value = "Value";

            public const string SqlCmdMetaData = "SqlCmdMetaData";            
        }
    }
}
